package com.junbao.message.ui.dto;

import net.sf.json.JSONObject;

import com.junbao.commom.exception.JunBaoException;
import com.junbao.commom.util.JsonUtils;
import com.junbao.message.domain.enums.NotifyStatus;
import com.junbao.message.domain.enums.NotifyWay;
import com.junbao.message.domain.model.NotifyMessage;

public class SendMessage extends BaseMessage{

	public SendMessage(String requestData) throws JunBaoException, Exception{
		requestDateCheck(requestData);
		JSONObject source = JSONObject.fromObject(requestData);
		NotifyMessage notifyMessage = new NotifyMessage(source.getString("message_no"), NotifyWay.REST, source.getString("notify_data"), source.getString("notify_url"));
		notifyMessage.setRetryMaxCount(source.getInt("retry_max_count"));
		notifyMessage.setNotifyStatus(NotifyStatus.WAIT_SEND);
		super.setNotifyMessage(notifyMessage);
	}
	
	@Override
	public void requestDateCheck(String requestDataSource) throws JunBaoException,Exception{
		JSONObject requestData = JSONObject.fromObject(requestDataSource);
		JsonUtils.containsKeysAndKeyValueIsEmpty(requestData, "message_no","notify_way","notify_data_type","notify_url","notify_data","retry_max_count"); 
	}
	
}
